package candidate_43148;

import java.util.Scanner;

public class ArrayOfCandidate_43148 {
	int n;
	int choose;
	Candidate_43148[] a = new Candidate_43148[20];

	public void input() {
		Scanner kb = new Scanner(System.in);
		do {
			System.out.print("Enter n:");
			n = kb.nextInt();
		} while (n > 20 || n < 0);
		for (int i = 0; i < n; i++) {
			System.out.print("Choose A or B (1/2) :");
			try {
				choose = kb.nextInt();
			} catch (Exception e) {
				System.out
						.println("Number is invalid. Default Candidate B is creat !");
			}
			if (choose == 1) {
				CandidateA_43148 h = new CandidateA_43148();
				h.input();
				a[i] = h;
			} else {
				CandidateB_43148 h = new CandidateB_43148();
				h.input();
				a[i] = h;
			}
		}
	}

	public void output() {
		for (int i = 0; i < n; i++)
			System.out.print(a[i].toString());
	}

	public void studentPass() {
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (a[i].average() >= 5)
				count++;
		}
		System.out.println("The number of student pass is : " + count);
	}

	public void infoStudentPass() {
		System.out.println("Infomation of Student Pass");
		for (int i = 0; i < n; i++) {
			if (a[i].average() >= 5)
				System.out.println(a[i].toString());
		}
	}

	public static void main(String args[]) {
		ArrayOfCandidate_43148 k = new ArrayOfCandidate_43148();
		k.input();
		k.output();
		k.studentPass();
		k.infoStudentPass();

	}

}
